﻿using M_Process.API.Appliction.Command.ProcessRouteCommand;
using M_Process.Repository.ProcessInterface;
using MediatR;

namespace M_Process.API.Appliction.CommandHandlers.ProcessRouteHandler
{
    /// <summary>
    /// 批量删除工艺信息
    /// </summary>
    public class ProcessRouteDeleteAllCommandHandler : IRequestHandler<ProcessRouteDeleteAllCommand, int>
    {
        private readonly IProcessRouteRepository _processRouteRepository;
        public ProcessRouteDeleteAllCommandHandler(IProcessRouteRepository processRouteRepository)
        {
            _processRouteRepository = processRouteRepository;
        }


        public async Task<int> Handle(ProcessRouteDeleteAllCommand request, CancellationToken cancellationToken)
        {
          
            foreach (var item in request.ProcessRouteId)
            {
                var delall = await _processRouteRepository.GetModelsAsync(item);
                delall.IsDeleted = true;
                await _processRouteRepository.UpdateAsync(delall);
            }
            return 1;
        }
    }
}
